package com.xxx.meter.ui.meter.switchgear.home;

import android.support.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.xxx.meter.R;
import com.xxx.meter.model.data.swt.SwitchEntry;
import com.xxx.meter.model.http.bean.MachineChildBean;

import java.util.ArrayList;
import java.util.List;

public class MeterSwitchgearAdapter extends BaseQuickAdapter<MachineChildBean, BaseViewHolder> {

    private List<SwitchEntry.DataItemEntry> list;

    public void setList(List<SwitchEntry.DataItemEntry> list) {
        this.list.clear();
        this.list.addAll(list);
        notifyDataSetChanged();
    }

    public MeterSwitchgearAdapter(@Nullable List<MachineChildBean> data) {
        super(R.layout.item_machine, data);
        list = new ArrayList<>();
    }

    @Override
    protected void convert(BaseViewHolder helper, MachineChildBean item) {
        boolean b = false;
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getEquipmenttypekey().equals(item.getType()) &&
                        list.get(i).getEquipmentkey().equals(item.getId())) {
                b = true;
                break;
            }
        }
        helper.setText(R.id.item_machine_text, item.getName())
                .setImageResource(R.id.item_machine_image, b ? R.mipmap.tag1 : R.mipmap.tag2);
    }
}
